/**
 * Page: sprite
 * Author: 吴建涛(fortomorrow@163.com)
 * Date: Mon Dec 22 23:18:50     2014
 */
require.config({
    baseUrl: './sprite',
    shim: {
        "jquery": {
            "exports": '$'
        },
        "underscore": {
            "deps": ['jquery'],
            "exports": '_'
        }
    },
    paths: {
        "jquery": "lib/jquery.min",
        "underscore": "lib/underscore-min"
    }
});

require(['./mods/drop',
        './mods/file-parser',
        './mods/canvas',
        './mods/sprite-config'], function(Drop, FileParser, DisplayCanvas, Config) {
    var drop = new Drop({
        el: '.input-area',
        input : '#J_file'
    });

    var parser = new FileParser();

    var canvas = new DisplayCanvas({
        el    : '.preview'
    });

    drop.on('file:dropped', function(args) {
        parser.fire('add:file', args);
    });

    parser.on('add:to:canvas', function(args) {
        canvas.fire('add:to:canvas', args);
    });

    var config = new Config({
        canvas: canvas
    });

    canvas.on('afterChange:css', function(e) {
        $('#J_CSS').val(e.newVal);
        var imgData = canvas.getDownloadFile('png');
        $('.download').attr('href', imgData);
        //$('.img-preview').attr('src', imgData);
        $('.download').show();
    });
});

